<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ page import="org.springframework.context.ApplicationContext" %>
<%@page import="java.net.URLDecoder"%>
<%@ page import="com.sz.ticket.dao.ITicketDAO" %>
<%@ page import="com.sz.common.SZUtility" %>
<%@page import="com.sz.business.dao.IBusinessDAO"%>
<%@ page import="org.springframework.context.ApplicationContext" %>
<%@ page import="com.sz.common.ICommonDAO" %>

<%
//*****************************************************考自checkTicket_Business.jsp  修改时要注意

String title = "客户核单";
String ticket_id = request.getParameter("ticket_id");
String src = "page/viewTicket.jsp?ticket_id="+ticket_id + "&show_title=0&show_confirm_title=0";

String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String userid = (String)session.getAttribute("userid");

String error = "";

String final_callback = request.getParameter("final_callback");

ServletContext servletContext = request.getSession().getServletContext(); 
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
ICommonDAO dao = (ICommonDAO) context.getBean("CommonDAO");
List list = dao.getDicValueList("CHECK_FLAG");

StringBuffer buf = new StringBuffer();
buf.append("select t.BUSINESS_ID, t.CHECK_C_FLAG, t.CHECK_C_TIME, t.CHECK_C_TOTAL, t.CHECK_C_NUMBER, t.CHECK_C_STAFFNUM,");  //此行6个
buf.append("t.CHECK_C_REMARK, t.CHECK_C_COMMENT, m.name check_c_manager_str "); 
buf.append(" from ticket t, manager m where t.check_c_manager=m.manager_id(+) and ticket_id="+ticket_id); //一定要有(+)
Map map = (Map)dao.queryForObject(buf.toString());
if (map==null) map = new HashMap(); //后改的，免得下面报错。不行大动了 ，不要奇怪。。。

String check_c_flag 			= SZUtility.toString(map.get("CHECK_C_FLAG"));
String check_c_time 			= SZUtility.toString(map.get("CHECK_C_TIME"));
String check_c_total 			= SZUtility.toString(map.get("CHECK_C_TOTAL")); 
String check_c_number 			= SZUtility.toString(map.get("CHECK_C_NUMBER"));
String check_c_staffnum 		= SZUtility.toString(map.get("CHECK_C_STAFFNUM"));
String check_c_remark 			= SZUtility.toString(map.get("CHECK_C_REMARK"));
String check_c_comment 			= SZUtility.toString(map.get("CHECK_C_COMMENT"));
String check_c_manager_str 		= SZUtility.toString(map.get("CHECK_C_MANAGER_STR"));

if(check_c_total.length() == 0) 			check_c_total="0";

if(check_c_staffnum.length() == 0) 			check_c_staffnum="0";
if(check_c_number.length() == 0) 			check_c_number="0";

//商家
String business_id = SZUtility.toString(map.get("BUSINESS_ID"));
if(business_id.equals("")) {
	error = "订单信息错误,商家ID为空";
} else {
	String sql = "select lock_manager from business where business_id=" + business_id;
	Map b = (Map)dao.queryForObject(sql);
	if(SZUtility.toString(b.get("LOCK_MANAGER")).equals("")) {
		error = "请先锁定商家";
	} else if(b.get("LOCK_MANAGER").toString().equals(userid) == false) {
		error = "订单的商家被他人锁定，不能进行核单操作";
	}	
}

String style1 = "width: 120px;";
String style2 = "font-size: 12px";
%>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<link href="<%= request.getContextPath() %>/css/main.css" rel="stylesheet" type="text/css" />
		<base href="<%=basePath%>" target="_self">
		<title><%=title%></title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="">
		<meta http-equiv="description" content="客户核单" >
	</head>
	
	<body onload="onLoad()">
		<script type="text/javascript" src="js/calendar.js"></script>
		<script type="text/javascript" src="js/utility.js"></script>
		<table width="100%">
		  <tr>
		  	<td class="title0" ><%=title%></td>		  	
	  	  </tr>	  	
	  	</table>
	  	
	  	<iframe id="iframe" frameborder="0" src="<%=src%>" width="100%" height="412px"> </iframe>  
  				
  		<form id="form" method="post" action="ticket/checkTicket.exec?OPERATE_TYPE=CHECK&from=1" onsubmit="return check()">
  		<input type="hidden" id="ticket_id" name="ticket_id" value="<%=ticket_id%>" >
  		<input type="hidden" id="business_response" name="business_response" > <!-- 预订结果 提前前的check函数会赋值 -->
  		<input type="hidden" id="final_callback" name="final_callback" value="<%=final_callback%>" >
  		
  		<table  width="100%" border="0" cellpadding="0" cellspacing="0" style="line-height:30px; padding-left:12">
		  <tr>
		  	<td colspan="8" align="left">客户核单信息</td>		  	
	  	  </tr>
	  	  
	  	  <tr>
	  	  	<td>消费金额</td>
	  	  	<td>
	  			<input type="text" id="check_c_total" name="check_c_total" value="<%=check_c_total%>" style="<%=style1%>" >
	  		</td>
	  		
	  		<td>就餐桌数</td>
	  	  	<td>
	  			<input type="text" id="check_c_number" name="check_c_number" value="<%=check_c_number%>" style="<%=style1%>" >
	  		</td>
	  		
	  		<td>就餐人数</td>
	  	  	<td>
	  			<input type="text" id="check_c_staffnum" name="check_c_staffnum" value="<%=check_c_staffnum%>" style="<%=style1%>" >
	  		</td>
	  		
	  		<td>客户评价</td>
	  	  	<td>
	  			<input type="text" id="check_c_remark" name="check_c_remark" value="<%=check_c_remark%>" style="<%=style1%>" >
	  		</td>
	  		
	  	  </tr>
	  	  
	  	   <tr>
	  	  	<td>客户核单标志</td>
	  	  	<td>
	  			<select id="check_c_flag" name="check_c_flag" style="<%=style1%>" >
	  			  <%
				   String value = null;
				   String text = null;
				   boolean b = false;
				   %>
				   
				   <%
				   for(int n = 0; n < list.size(); ++n) { 
					   
					   Map tmp = (Map)list.get(n);
					   value = tmp.get("DIC_VALUE").toString();
					   text = tmp.get("DIC_TEXT").toString();
					   b = value.equals(check_c_flag);
				   %>
				   <option <%if(b){%> selected="selected" <%}%>
				     value="<%=value%>"><%=text%>
				   </option>
				   <%}%>
	  			</select>
	  		</td>
	  		
	  		<td>商家核单操作员</td>
	  	  	<td>
	  			<input type="text" id="check_c_manager" name="check_c_manager" value="<%=check_c_manager_str%>" style="<%=style1%>" >
	  		</td>
	  		
	  		<td>商家核单时间</td>
	  	  	<td>
	  			<input type="text" id="check_c_time" name="check_c_time" value="<%=check_c_time%>" style="<%=style1%>" >
	  		</td>
	  		
	  	  </tr>
	  	  
	  	  <tr>	  	  	
	  		
	  		<td>核单结果描述</td>
	  	  	<td colspan="3">
	  			<input type="text" id="check_c_comment" name="check_c_comment" value="<%=check_c_comment%>" style="<%=style1%>">
	  		</td>	  		
	  		
	  	  </tr>	  	  
	  	</table>
	  	<br/>
	  	<table width="100%">
	  		<tr align="center">
	  			<td>
	  				<input type="submit" id="checkTicket" value="确认" style="width: 80px"/>
	  			</td>
	  		</tr>
	  		
	  	</table>
  		
  		</form>
  	
  	<SCRIPT LANGUAGE="JavaScript">
  	  	
  	function check() {  		
  		var tmp;
  		
  		tmp = document.getElementById("check_c_total").value;
		if(IsPlusNumeric(tmp)== false) {
  			alert("请正确输入'消费金额'");
  			return false;
		}
		
  		tmp = document.getElementById("check_c_number").value;
		if(IsInteger(tmp)== false) {
  			alert("请正确输入'就餐桌数'");
  			return false;
		}
		
		tmp = document.getElementById("check_c_staffnum").value;
		if(IsInteger(tmp)== false) {
  			alert("请正确输入'就餐人数'");
  			return false;
		}
		
		tmp = document.getElementById("check_c_flag").value;
		if(tmp == null || tmp == "0") {
  			alert("请选择'客户核单标志'");
  			return false;
		}
		
		tmp = document.getElementById("iframe").contentWindow.document.getElementById("business_response").value;
		document.getElementById("business_response").value = tmp;	  		
  	}
  	
  	function onLoad() {
  		var error = "<%=error%>";
  		if(error != "") {
  			document.getElementById("checkTicket").disabled = true;
  			alert(error);
  		}
  	}
  		
  	</SCRIPT>
	</body>
</html>
